﻿Public Class frmAD_LapPhieuThuTien
    Public _maDangTin As Integer
    Public Property MaDangTin() As Integer
        Get
            Return _maDangTin
        End Get
        Set(ByVal value As Integer)
            _maDangTin = value
        End Set
    End Property
    Public _maSinhVien As Integer
    Public Property MaSinhVien() As Integer
        Get
            Return _maSinhVien
        End Get
        Set(ByVal value As Integer)
            _maSinhVien = value
        End Set
    End Property
    Public phieuDTO As New PhieuGioiThieuDTO
    Public phieuBUS As New PhieuGioiThieuBUS
    Private Sub frmAD_LapPhieuThuTien_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtMaTinNha.Text = MaDangTin.ToString()
        cbTimTheo.Items.Add("Mã sinh viên")
        cbTimTheo.Items.Add("CMND")
        cbTimTheo.Items.Add("Họ tên")
        cbTimTheo.Items.Add("Email")
        cbTimTheo.Items.Add("Điện thoại")
        cbTimTheo.SelectedIndex = 2
    End Sub

    Private Sub dgv_RowEnter(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.RowEnter
        Try
            txtMaSV.Text = dgv.Rows(e.RowIndex).Cells("MaSinhVien").Value.ToString()
        Catch ex As Exception

        End Try

    End Sub
    Public svDTO As New SinhVienDTO
    Public svBUS As New SinhVienBUS
    Public tableSV As New DataTable
    Private Sub btnTaiDS_Click(sender As System.Object, e As System.EventArgs) Handles btnTaiDS.Click
        tableSV = svBUS.GetAll()
        dgv.DataSource = tableSV
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If txtGiaTien.Text = "" Or txtMaSV.Text = "" Or txtMaTinNha.Text = "" Then
            MessageBox.Show("Vui lòng nhập đầy đủ thông tin", "Thông tin")
        Else
            phieuDTO.MaDangTin = MaDangTin
            phieuDTO.MaSinhVien = Convert.ToInt32(txtMaSV.Text)
            phieuDTO.MaPhieu = 1
            phieuDTO.GiaTien = Convert.ToInt32(txtGiaTien.Text)
            phieuDTO.NgayLap = DateTime.Now.Date.ToString("dd/MM/yyyy")
            Dim frm1 As New frmAD_LapPhieuThuTien_ChiTietPhieu
            If phieuBUS.Insert(phieuDTO) = True Then
                MessageBox.Show("Thành công", "Thông báo")
                frm1.MaSinhvien = phieuDTO.MaSinhVien
                frm1.MaDangTin = phieuDTO.MaDangTin
                frm1._phieuDTO = phieuDTO
                frm1.ShowDialog()
            End If
        End If
    End Sub
    Private Sub btnTim_Click(sender As System.Object, e As System.EventArgs) Handles btnTim.Click
        If txtTuKhoa.Text = "" Then
            MessageBox.Show("Vui lòng nhập từ khóa", "Thông báo")
        Else
            If cbTimTheo.Text = "Mã sinh viên" Then
                svDTO.MaSinhVien = Convert.ToInt32(txtTuKhoa.Text)
                tableSV = svBUS.TimMaSinhVien(svDTO)
                dgv.DataSource = tableSV
            End If
            If cbTimTheo.Text = "Họ tên" Then
                svDTO.HoTen = txtTuKhoa.Text
                tableSV = svBUS.TimHoTen(svDTO)
                dgv.DataSource = tableSV
            End If
            If cbTimTheo.Text = "Email" Then
                svDTO.Email = txtTuKhoa.Text
                tableSV = svBUS.TimEmail(svDTO)
                dgv.DataSource = tableSV
            End If
            If cbTimTheo.Text = "Điện thoại" Then
                svDTO.DienThoai = txtTuKhoa.Text
                tableSV = svBUS.TimDienThoai(svDTO)
                dgv.DataSource = tableSV
            End If
            If cbTimTheo.Text = "CMND" Then
                svDTO.CMND = txtTuKhoa.Text
                tableSV = svBUS.TimCMND(svDTO)
                dgv.DataSource = tableSV
            End If
        End If
    End Sub

    Private Sub txtGiaTien_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtGiaTien.TextChanged

    End Sub

    Private Sub txtGiaTien_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtGiaTien.KeyPress
        If (Not Char.IsNumber(e.KeyChar) And Not Char.IsControl(e.KeyChar)) Then
            e.Handled = True
        End If
    End Sub
End Class